package android.example.graphictest.linedraw;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

public class DrawLine extends View implements Runnable
{
	Paint mPaint            = null;
	public static float w   = 0;
	public static float h   = 0;
	public static int count = 0;
	public static int j     = 0;
	public static long startTime = 0;
	public static long stopTime  = 0;
	public static float fps      = 0;
	public static int   frame    = 0;
	public static float totalFPS = 0;
	
	public DrawLine(Context context)
	{
		super(context);
		mPaint = new Paint();
		h      = (float)Draw2D.screenHeight;
		w      = (float)Draw2D.screenWidth;
		new Thread(this).start();
	}
	public void run()
	{
		while(!Thread.currentThread().isInterrupted())
		{
			try
			{
				Thread.sleep(10);
			}
			catch(InterruptedException e)
			{
				Thread.currentThread().interrupt();
			}
			postInvalidate();
		}
	}
	public void onDraw(Canvas canvas )
	{
		super.onDraw(canvas);
		if(startTime == 0)
		{
			startTime = System.currentTimeMillis();
		}
		mPaint.setColor(Color.MAGENTA);
		mPaint.setStrokeWidth(2);
		for(int i = 0; i <= frame ; i++)
		{
		    canvas.drawLine(w/2, h/2, (float)(w*Math.random()),(float)(h*Math.random()) , mPaint);
		}
		
		stopTime = System.currentTimeMillis();
		if(frame > 150)
		{
			fps       = (float)(1000*frame)/(float)(stopTime - startTime - 10*frame);
			startTime = 0;
			frame     = 0;
			if(count > 1 && count < 7 )
			{
				totalFPS += fps;
			}
			
			count++;
		}
		frame++;
	}

}
